<?php
namespace product\service;

use herosphp\core\Loader;
use herosphp\utils\Page;
use models\ProductModel;
use utils\x1\MyFunction;
use herosphp\cache\CacheFactory;
use herosphp\core\WebApplication;
use herosphp\bean\Beans;

Loader::import('utils.x1.MyFunction');

class ProductService extends CommonService
{
    private $thisModel = null;
    private static $__cacheCtrl;

    public function __construct($model)
    {
        parent::__construct($model);
        $this->thisModel = Loader::model('product');
        //客户机运行不需要缓存
        if (self::$__cacheCtrl == null && !defined('RUN_CLI')) {
            $config = WebApplication::getInstance()->getConfigs();
            $cachetype = $config['cache_type'];

            self::$__cacheCtrl = CacheFactory::create($cachetype);
        }
    }

    //根据类型、品名、厂家、牌号，货品规格来生成货号
    public function getProductNo($data)
    {

        $str = join($data, '-');//"$type_name,$product_name,$factory_name,$brand_name,$pkg_size";

        $md5_star = substr(md5($str), 8, 16);

        return 'A' . base_convert($md5_star, 16, 10);

    }

    //销售中/仓库中的商品搜索
    public function searchBySaleAndStore($pagesize, $page, $search_arr)
    {
        $offset = $pagesize * ($page - 1); //计算记录偏移量


        $whereSql = "And product.app_id='" . appId() . "' And product.is_delete='0' ";

        //选择导出 add By Laoliu
        if ($search_arr['id']) {
            $whereSql .= " AND product.id in {$search_arr['id']}";
        }

        if (in_array($search_arr['select_mix_option1'], array('product_no', 'type_name', 'factory_name', 'product_name', 'brand_name'))) {
            switch($search_arr['select_mix_option1']){

                case 'product_no':
                    $whereSql .= " And product_no like '%{$search_arr['select_mix_option_value1']}%'";
                    break;

                case 'type_name':
                    if($search_arr['select_mix_option_value1']!=''){

                        $whereSql .= " And type_name like '%{$search_arr['select_mix_option_value1']}%'";
                    }
                    break;

                case 'factory_name':
                    $whereSql .= " And factory_name like '%{$search_arr['select_mix_option_value1']}%'";
                    break;

                case 'product_name':
                    $whereSql .= " And product_name like '%{$search_arr['select_mix_option_value1']}%'";
                    break;

                case 'brand_name':
                    $whereSql .= " And brand_name like '%{$search_arr['select_mix_option_value1']}%'";
                    break;
            }
        }
        if ($search_arr['delivery_way'] != '' && $search_arr['delivery_way'] != 'all') {

            $whereSql .= " And product.delivery_way=" . $search_arr['delivery_way'];
        }

        if ($search_arr['status'] != '' && $search_arr['status'] != 'all') {

            $whereSql .= " And product.status='{$search_arr['status']}'";
        }

        $count_sql = "Select  count(*)
                From product Left Join repertory On product.repertory_id=repertory.id
                Where 1 $whereSql";

        $total = $this->thisModel->getDB()->excute($count_sql)->fetchColumn();

        //分页查询
        $pageinationSql = isset ($offset) ? " Limit $offset,$pagesize" : " Limit 0,$pagesize";

        $sql = "Select product.*,repertory.name As repertory_name
                 From product Left Join repertory On product.repertory_id=repertory.id
                Where 1 $whereSql
                Order By edittime Desc $pageinationSql";

        $items = $this->thisModel->getDB()->excute($sql)->fetchAll($fetch_style = 2);

        return array("items" => $items, "total" => $total);
    }

    //商品搜索
    public function search($pagesize, $page, $search_arr)
    {
        $offset = $pagesize * ($page - 1); //计算记录偏移量

        $status = ProductModel::STATUS_ON_SHELF;


        $whereSql = "And product.app_id='" . appId() . "' And product.is_delete='0'  And product.status='{$status}'";

        if ($search_arr['delivery_place'] != '') {//交收地

            $whereSql .= " And repertory.address like 'city\":\"%{$search_arr['delivery_place']}%'\"";
        }
        if ($search_arr['delivery_way'] != '') {//交收方式

            $whereSql .= " And product.delivery_way = '{$search_arr['delivery_way']}'";
        }
        if ($search_arr['type_name'] != '') {

            $whereSql .= " And product.type_name = '{$search_arr['type_name']}'";
        }
        if ($search_arr['factory_name'] != '') {

            $whereSql .= " And product.factory_name like '%{$search_arr['factory_name']}%'";
        }
        if ($search_arr['product_name'] != '') {

            $whereSql .= " And product.product_name = '{$search_arr['product_name']}'";
        }
        if ($search_arr['brand_name'] != '') {

            $whereSql .= " And product.brand_name like '%{$search_arr['brand_name']}%'";
        }
        if ($search_arr['kw'] != '') {

            $whereSql .= " And ( product.product_name like '%{$search_arr['kw']}%'";
            $whereSql .= " Or product.factory_name like '%{$search_arr['kw']}%'";
            $whereSql .= " Or product.brand_name like '%{$search_arr['kw']}%' )";
        }
        if ($search_arr['repertory_city_name'] != '') {

            $whereSql .= " And (repertory.dist_txt!=''  And repertory.city_txt ='{$search_arr['repertory_city_name']}')";

            $whereSql .= " Or (repertory.dist_txt=''  And repertory.prov_txt ='{$search_arr['repertory_city_name']}')";

        }
        if (($search_arr['start_price'] != '' || $search_arr['end_price'] != '')) {

            $whereSql .= " And " . MyFunction::betweenSql('product.sales_price', $search_arr['start_price'], $search_arr['end_price']);
        }

        //分页查询
        $pageinationSql = isset ($offset) ? " Limit $offset,$pagesize" : " Limit 0,$pagesize";

        $orderSql = 'Order By product.edittime Desc';

        if ($search_arr['order_name'] != '') {

            $order_way=$search_arr['order_way']=='desc'?'Desc':'Asc';

            switch ($search_arr['order_name']) {
                case 'all':

                    $orderSql = "Order By product.edittime {$order_way}";

                    break;
                case 'price':
                    $orderSql = "Order By product.sales_price {$order_way}";

                    break;
                case 'qty':
                    $orderSql = "Order By product.quantity {$order_way}";

                    break;
                default:
                    $orderSql = "Order By product.edittime {$order_way}";

            }

        }
        //计算总数
        $sql = "Select product.*,repertory.address,repertory.prov_txt As repertory_prov,repertory.city_txt As repertory_city,repertory.dist_txt As repertory_dist
                From product Left Join repertory On product.repertory_id=repertory.id
                Where 1 $whereSql";

        $items = $this->thisModel->getDB()->excute($sql)->fetchAll($fetch_style = 2);

        foreach ($items as $k => $item) {

            if ($search_arr['member_id'] != '') {
                //发布方式：1=公开,2=指定会员，3=公开和指定会员

                if($item['publish_way']=='2'){

                    $productMember = $this->getProductMember($item['id'], $search_arr['member_id']);

                    if (!$productMember) {

                        unset($items[$k]);
                    }
                }
            }

            $items[$k]['quantity'] = bcsub($items[$k]['quantity'] , $items[$k]['freeze_quantity'],3);

            if($items[$k]['quantity']==0){
                unset($items[$k]);

            }
        }
        $total=count($items);
        //计算总数

        $sql = "Select product.*,repertory.address,repertory.prov_txt As repertory_prov,repertory.city_txt As repertory_city,repertory.dist_txt As repertory_dist
                From product Left Join repertory On product.repertory_id=repertory.id
                Where 1 $whereSql
                $orderSql  $pageinationSql";

        $items = $this->thisModel->getDB()->excute($sql)->fetchAll($fetch_style = 2);

        foreach ($items as $k => $item) {

            if ($search_arr['member_id'] != '') {
                //发布方式：1=公开,2=指定会员，3=公开和指定会员

                if($item['publish_way']=='2'){

                    $productMember = $this->getProductMember($item['id'], $search_arr['member_id']);

                    if ($productMember) {

                        $items[$k]['sales_price'] = $productMember['sales_price'];

                        $items[$k]['delivery_way'] = $productMember['delivery_way'];

                    }else{

                        unset($items[$k]);
                        continue;
                    }

                }elseif($item['publish_way']=='3'){

                    $productMember = $this->getProductMember($item['id'], $search_arr['member_id']);
                    if ($productMember) {

                        $items[$k]['sales_price'] = $productMember['sales_price'];

                        $items[$k]['delivery_way'] = $productMember['delivery_way'];
                    }

                }

            }


            if($items[$k]['repertory_dist']==''){

                $items[$k]['address'] = $items[$k]['repertory_prov'].''.$items[$k]['repertory_city'];

            }else{

                $items[$k]['address'] = $items[$k]['repertory_city'].''.$items[$k]['repertory_dist'];
            }

            $items[$k]['quantity'] = bcsub($items[$k]['quantity'] , $items[$k]['freeze_quantity'],3);

            if($items[$k]['quantity']==0){
                unset($items[$k]);
            }
        }


        $pageHandler = new Page($total, $pagesize, $page);

        $pageData = $pageHandler->getPageData(DEFAULT_PAGE_STYLE);

        return array("items" => $items, "pageData" => $pageData, "total" => $total);
    }

    /**
     * 根据产品id和会员id获取产品会员价和交收方式
     * @param $productId
     * @param $memberId
     * @return mixed
     */
    public function getProductMember($productId, $memberId)
    {

        $productMemberModel = Loader::model('productMember');

        $item = $productMemberModel->getItem(array('product_id' => $productId, 'member_id' => $memberId, 'is_delete' => 0));

        return $item;
    }


    /**
     * 根据产品id和会员id获取产品数据
     * @param $productId
     * @param $memberId
     * @return mixed
     */
    public function getProduct($productId, $memberId)
    {
        $whereSql = "And product.id='$productId'";
        $sql = "Select product.*,repertory.address
                From product Left Join repertory On product.repertory_id=repertory.id
                Where 1 $whereSql";

        $items = $this->thisModel->getDB()->excute($sql)->fetchAll($fetch_style = 2);
        $item = $items[0];
        //用指定会员报价数据来替换原价
        if ($memberId != '') {

            $productMember = $this->getProductMember($productId, $memberId);

            if ($productMember) {

                $item['sales_price'] = $productMember['sales_price'];

                $item['delivery_way'] = $productMember['delivery_way'];
            }
        }

        return $item;
    }

    /**
     * 根据产品id查询所在仓库信息
     * @param $productId
     * @return mixed
     */
    public function getRepertoryByProductId($productId)
    {

        $whereSql = "And product.id='$productId'";
        $sql = "Select repertory.address As repertory_address,repertory.name As repertory_name,street,repertory.contact,repertory.contact_mobile
                From product Left Join repertory On product.repertory_id=repertory.id
                Where 1 $whereSql";

        $items = $this->thisModel->getDB()->excute($sql)->fetchAll($fetch_style = 2);

        if ($items[0]) {

            $items[0]['repertory_address'] = $items[0]['repertory_address'] . '' . $items[0]['street'];
            unset($items[0]['street']);

        }

        return $items[0];

    }

    //根据货号筛选商品,供后台管理添加订单使用
    public function getProducts($product_no, $member_id = '')
    {
        $items = Loader::model('product')->getItems(array('product_no' => '%' . $product_no . '%'), '', '', '', '', '');

        if ($member_id != '') {

            foreach ($items as $k => $item) {
                $items[$k]['orgin_sales_price'] = $items[$k]['sales_price'];

                $productMember = $this->getProductMember($item['id'], $member_id);

                if ($productMember) {

                    $items[$k]['sales_price'] = $productMember['sales_price'];
                } else {
                    $items[$k]['sales_price'] = $items[$k]['orgin_sales_price'];

                }

            }
        }
        return $items;
    }


    /**
     * 根据id列和member_id来查商品
     * @param $ids
     * @param string $memberId
     * @return mixed
     */
    public function getProductsByIds($ids, $memberId = '')
    {

        $whereSql = "And product.id In ('" . join("','", $ids) . "')";

        $sql = "Select product.*,repertory.name As repertory_name,repertory.dist_txt,repertory.city_txt
                From product Left Join repertory On product.repertory_id=repertory.id
                Where 1 $whereSql";

        $items = $this->thisModel->getDB()->excute($sql)->fetchAll($fetch_style = 2);


        foreach ($items as $k => $item) {
            //用指定会员报价数据来替换原价
            if ($memberId != '') {

                $productMember = $this->getProductMember($item['id'], $memberId);

                if ($productMember) {

                    $items[$k]['sales_price'] = $productMember['sales_price'];

                    $items[$k]['delivery_way'] = $productMember['delivery_way'];
                }
            }

            $items[$k]['address'] = $items[$k]['city_txt'].''.$items[$k]['dist_txt'];

        }

        return $items;

    }

    /**
     * 使其商品上架
     * @param $ids
     */
    public function onShelf($ids)
    {

        $bool = Loader::model('product')->updates(array('status' => 1), array('id' => array('$in' => $ids) ));

        return $bool;

    }

    /**
     * 使其商品下架
     * @param $ids
     */
    public function offShelf($ids)
    {

        $bool = Loader::model('product')->updates(array('status' => 2), array('id' => array('$in' => $ids) ));

        return $bool;
    }

    /**
     * 冻结一部库存
     * @param $product_id 　商品id
     * @param $freeze_quantity 冻结数量
     * @return bool
     */
    public function freezeStock($product_id, $freeze_quantity)
    {

        $item = Loader::model('product')->getItem(array('id' => $product_id), 'quantity,freeze_quantity');

        //下单
        if (($item['quantity'] - $item['freeze_quantity']) - $freeze_quantity >= 0) {
            //可用库存为0时，自动下架
            if(($item['quantity'] - $item['freeze_quantity']) - $freeze_quantity== 0){

              $this->offShelf(array($product_id));//下架
            }

            return Loader::model('product')->increase('freeze_quantity', $freeze_quantity, $product_id);

        } else {

            return false;
        }
    }

    /**
     * 解冻一部库存
     * @param $product_id 　商品id
     * @param $freeze_quantity 解冻数量
     * @param $only_thaw_freezequantity 仅解冻"冻结数量"
     * @return bool
     */
    public function thawStock($product_id, $thaw_quantity, $only_thaw_freezequantity = false)
    {

        $item = Loader::model('product')->getItem(array('id' => $product_id), 'freeze_quantity');
        if ($item['freeze_quantity'] - $thaw_quantity >= 0) {
            //取消订单
            if ($only_thaw_freezequantity) {

                //可用库存大于0时，自动上架
                if(($item['quantity'] - $item['freeze_quantity']) - $thaw_quantity> 0){

                    $this->onShelf(array($product_id));//上架
                }

                return Loader::model('product')->reduce('freeze_quantity', $thaw_quantity, $product_id);

            } else {
                //交易完成
                $this->beginTransaction();
                if ($this->reduce('freeze_quantity', $thaw_quantity, $product_id) && $this->reduce('quantity', $thaw_quantity, $product_id)) {

                    $this->commit();
                    return true;

                } else {

                    $this->rollback();
                    return false;
                }

            }

        } else {

            return false;

        }

    }

    /**
     * 更新库存
     * @param $product_id 　商品id
     * @param $quantity 数量
     * @return bool
     */
    public function updateStock($product_id, $quantity)
    {

        $bool = Loader::model('product')->update(array('quantity' => $quantity), $product_id);

        return $bool;

    }

    /**
     * 最近指定用户
     * @return array
     */
    public function getRecentSpecifyMembers($memberIds = '')
    {

        $zNodes = array();

        $productMemberModel = Loader::model('productMember');
        $memberModel = Loader::model('member');

        $productMembers = $productMemberModel->getItems(array('app_id' => appId(), 'is_delete' => 0), 'member_id', array('edittime' => -1), 10, 'member_id');
        $ids = array();
        foreach ($productMembers as $k => $v) {

            $ids[] = $v['member_id'];
        }

        $members = $memberModel->getItems(array('app_id' => appId(), 'del_status'=>0,'status'=>1,'id' => array('$in' => array_unique($ids))));

        $zNodes[] = array('id' => 3242323333, 'pId' => 0, 'name' => "最近指定", 'open' => true);

        foreach ($members as $k => $v) {

            //$zNodes[] = array('id' => $v['id'], 'pId' => 3242323333, 'name' => "{$v['username']}");

            if (in_array($v['id'], $memberIds)) {

                $zNodes[] = array('id' => $v['id'], 'pId' => 3242323333, 'name' => "{$v['username']}", 'checked' => true);

            } else {

                $zNodes[] = array('id' => $v['id'], 'pId' => 3242323333, 'name' => "{$v['username']}");

            }
        }

        return $zNodes;

    }

    /**
     * 获取各分组会员zNodes数据，用于商品发布的指定用户tree
     * @param string $memberIds 初始化被选中的节点
     * @return string
     */
    public function getGroupMembers($memberIds = '')
    {
        $zNodes = array();

        $memberGroupModel = Loader::model('memberGroup');
        $memberModel = Loader::model('member');

        $memberGroups = $memberGroupModel->getItems(array('app_id' => appId(),'status'=>1));
        $groupIds = array();

        foreach ($memberGroups as $k => $v) {

            $groupIds[] = $v['id'];

            $zNodes[] = array('id' => $v['id'], 'pId' => 0, 'name' => "{$v['name']}", 'isParent'=>true);
        }
        //"未分组"分租
        $zNodes[] = array('id' => '9999999', 'pId' => 0, 'name' => "未分组", 'isParent'=>true);

        $members = $memberModel->getItems(array('app_id' => appId(), 'del_status'=>0,'status'=>1));//,'group_id' => array('$in' => $groupIds)

        foreach ($members as $k => $v) {

            $checked=(in_array($v['id'], $memberIds)) ?true:false;

            $pid = $v['group_id'];

            if($pid==''||$pid=='0'){

                $pid='9999999';
            }

            $zNodes[] = array('id' => $v['id'], 'pId' => $pid, 'name' => "{$v['username']}", 'checked' => $checked);


        }
        //checked:true
        return json_encode(array_merge($this->getRecentSpecifyMembers(), $zNodes));
    }


    public function getPublishWayIsMembers($productId)
    {
        $productMemberModel = Loader::model('productMember');

        $items = $productMemberModel->getItems(array('product_id' => $productId, 'is_delete' => 0));

        $publish_way_is_memberArr = [];

        foreach ($items as $item) {

            $publish_way_is_memberArr[] = $item['member_id'];

        }
        return $publish_way_is_memberArr;
    }

    public function getProduct2($id)
    {
        $productModel = Loader::model('product');

        $productMemberModel = Loader::model('productMember');

        $item = $productModel->getItem($id);

        $productMemberItem = $productMemberModel->getItem(array('product_id' => $id, 'is_delete' => 0));

        $item['member_sales_price'] = $productMemberItem['sales_price'];
        $item['member_delivery_way'] = $productMemberItem['delivery_way'];

        return $item;
    }

    public function add($data)
    {
        $productModel = Loader::model('product');

        $productMemberModel = Loader::model('productMember');

        $productModel->beginTransaction();

        $productData = $data;

        unset($productData['publish_way_is_members']);
        unset($productData['member_sales_price']);
        unset($productData['member_delivery_way']);
        $last_id = $productModel->add($productData);
        if (!$last_id) {

            $productModel->rollback();
            return false;
        }

        if ($data['publish_way_is_members'] != '') {

            $publish_way_is_memberArr = array_unique(explode(',', $data['publish_way_is_members']));

            foreach ($publish_way_is_memberArr as $k => $v) {

                if (!$productMemberModel->add(array('product_id' => $last_id, 'member_id' => $v, 'sales_price' => $data['member_sales_price'], 'delivery_way' => $data['member_delivery_way']))) {

                    $productModel->rollback();
                    return false;
                }

            }
        }
        $productModel->commit();

        return true;

    }

    public function update($data, $id)
    {
        $productModel = Loader::model('product');

        $productMemberModel = Loader::model('productMember');

        $productModel->beginTransaction();

        $productData = $data;

        unset($productData['publish_way_is_members']);
        unset($productData['member_sales_price']);
        unset($productData['member_delivery_way']);
        if (!$productModel->update($productData, $id)) {

            $productModel->rollback();
            return false;
        }
        if ($data['publish_way_is_members'] != '') {

            $publish_way_is_memberArr = array_unique(explode(',', $data['publish_way_is_members']));

            //首先删除全部数据
            $productMemberModel->updates(array('is_delete' => 1), array('product_id' => $id));

            //然后重建数据
            foreach ($publish_way_is_memberArr as $k => $v) {

                // if (!$productMemberModel->updates(array('member_id' => $v, 'sales_price' => $data['member_sales_price'], 'delivery_way' => $data['member_delivery_way'], 'is_delete' => 0), array('product_id' => $id, 'member_id' => $v))) {

                if (!$productMemberModel->add(array('product_id' => $id, 'member_id' => $v, 'sales_price' => $data['member_sales_price'], 'delivery_way' => $data['member_delivery_way']))) {
                    $productModel->rollback();
                    return false;
                }
                //}

            }
        }
        $productModel->commit();

        return true;
    }

    /**
     * 是否有商品在未完成订单中，一般用在下架商品之前的验证中
     * @param $productId
     * @return bool
     */
    public function validateProductInUnFinishedOrder($productId){

        $where_sql=" And p.id='{$productId}'";

        $sql="Select p.id,p.product_no,o.order_no From product As p Left Join trading_order_product As o_p On p.id=o_p.product_id
              Left Join trading_order As o On o.id=o_p.order_id Where (o.order_status!=7 And o.order_status!=8) {$where_sql}";

        $items = $this->thisModel->getDB()->excute($sql)->fetchAll($fetch_style = 2);

        return (count($items)>0)? $items[0]: false;
    }

    /**
     * 依据冻结数量验证输入数量，输入数量不能小于此时的冻结数量
     * @param $quantity
     */
    public function validateQtyFromFreezeQty($quantity, $productId)
    {

        $productModel = Loader::model('product');

        $item = $productModel->getItem($productId);

        return ($quantity >= $item['freeze_quantity']) ? true : false;

    }

    /**
     * 查询相同产品
     * @param $typeName
     * @param $producName
     * @param $factoryName
     * @param $brandName
     * @param $pkgSize
     */
    public function selectSameProduct($typeName, $productName, $factoryName, $brandName, $pkgSize, $id = '')
    {

        $productModel = Loader::model('product');
        if ($id == '') {
            $item = $productModel->getItem(array('type_name' => $typeName, 'product_name' => $productName, 'factory_name' => $factoryName, 'brand_name' => $brandName, 'pkg_size' => $pkgSize));

        } else {

            $item = $productModel->getItem(array('type_name' => $typeName, 'product_name' => $productName, 'factory_name' => $factoryName, 'brand_name' => $brandName, 'pkg_size' => $pkgSize, 'id' => "!{$id}"));

        }

        return $item ? true : false;
    }

    /**
     *　从商品表中获取厂家牌号数据
     */
    public function getMyTPFB()
    {
        $myTPFBArray = array();
        foreach ($this->thisModel->field("DISTINCT type_name")->find() as $k => $v) {
            $myTPFBArray['typeName'][] = $v['type_name'];

        }
        foreach ($this->thisModel->field("DISTINCT product_name")->where(array('status'=>'1'))->find() as $k => $v) {
            $myTPFBArray['productName'][] = $v['product_name'];

        }
        foreach ($this->thisModel->field("DISTINCT factory_name")->find() as $k => $v) {
            $myTPFBArray['factoryName'][] = $v['factory_name'];

        }
        foreach ($this->thisModel->field("DISTINCT brand_name")->find() as $k => $v) {
            $myTPFBArray['brandName'][] = $v['brand_name'];
        }
        //应对含直辖市情况sql
        foreach (Loader::model('repertory')->field("DISTINCT if(dist_txt='',prov_txt,city_txt) As city_txt ")->find() as $k => $v) {
            $myTPFBArray['repertoryCityName'][] = $v['city_txt'];
        }
        return $myTPFBArray;
    }

    public function handleMyTPFBArray($refresh = false)
    {

        $cache = self::$__cacheCtrl->baseKey('product')->ftype('product')->factor('tpfb_' . appId());
        $result = $cache->get();
        if (!$result || $refresh) {
            $result = $this->getMyTPFB();
            $cache->set(null, $result);
        }
        return $result;
    }

    /**
     * 计价类型
     * @param $k
     * @return mixed
     */
    public function getValuationTypeText($k = '__all')
    {
        $arr = array('0' => '普通新料', '1' => '粉料及弹性料', '2' => '太空包', '3' => '改性料');
        return $k == '__all' ? $arr : $arr[$k];
    }

    /**
     * 交收方式
     * @param $k
     * @return mixed
     */
    public function getDeliveryWayText($k = '__all')
    {

        $arr = array('0' => '卖家配送', '1' => '买家自提');
        return $k == '__all' ? $arr : $arr[$k];
    }

    /**
     * 发布方式
     * @param $k
     * @return mixed
     */
    public function getPublishWayText($k = '__all')
    {
        $arr = array('1' => '公开', '2' => '指定会员', '3' => '公开和指定会员');
        return $k == '__all' ? $arr : $arr[$k];
    }

    /**
     * 上架状态
     * @param $k
     * @return mixed
     */

    public function getStatusText($k = '__all')
    {
        $arr = array('1' => '上架中', '2' => '下架中');
        return $k == '__all' ? $arr : $arr[$k];
    }

}

